package com.mbti.youmore.entity.resp;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 用于封装Ajax响应数据的类
 *
 * @author 顾建平
 * @version 1.0
 * @since 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseData implements Serializable {

    /**
     * 结果码，成功=1，失败=0
     */
    private int code;
    /**
     * 显示信息，成功则显示"success"，失败则显示失败原因。
     */
    private String msg;
    /**
     * 数据对象，用于储存响应数据对象
     */
    private Object data;

    public static ResponseData success() {
        return new ResponseData(1, "success", null);
    }

    public static ResponseData success(Object data) {
        return new ResponseData(1, "success", data);
    }

    public static ResponseData fail(int code, String msg) {
        return new ResponseData(code, msg, null);
    }

}
